namespace Storage.Core
{
	internal class AddOrUpdateQuery : IStorageQuery
	{
		public AddOrUpdateQuery(PlainEntity entity)
		{
			Entity = entity;
		}

		public byte[] Serialize()
		{
			var serializer = new FastBinarySerializer(sizeof(byte) + Entity.EstimatedSerializedSize());
			serializer.Write(StorageOpCodes.AddOrUpdate).Write(Entity);
			return serializer.Buffer;
		}

		public static AddOrUpdateQuery Deserialize(IBinaryDeserializer ds)
		{
			return new AddOrUpdateQuery(PlainEntity.Deserialize(ds));
		}

		public PlainEntity Entity { get; private set; }
	}
}